﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//ref传进去的参数必须在调用前初始化，out不必
//ref传进去的参数在函数内部可以直接使用，而out不可
//ref传进去的参数在函数内部可以不被修改，但out必须在离开函数体前进行赋值
namespace Demo1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[6];
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请输入第"+(i+1)+"个数");
                arr[i] = int.Parse(Console.ReadLine());
            }
            int Rmax = arr[0];
            int Rmin = arr[0];
            double Ravg = 0;
            int Rsum = Rmine(arr,ref Rmax,ref Rmin,ref Ravg);
            Console.WriteLine("ref方法");
            Console.WriteLine("最大值:{0},最小值:{1},和:{2},平均数{3}",Rmax,Rmin,Rsum,Ravg);
            int Omax;
            int Omin;
            double Oavg;
            int Osum = Omine(arr,out Omax,out Omin,out Oavg);
            Console.WriteLine("out方法");
            Console.WriteLine("最大值:{0},最小值:{1},和:{2},平均数{3}", Omax, Omin, Osum, Oavg);
            Console.ReadKey();
        }
        static int Omine(int[]arr,out int max,out int min,out double avg) 
        {
            int sum = 0;
            max = arr[0];
            min = arr[0];
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i]>max)
                {
                    max = arr[i];
                }
                if (arr[i]<min)
                {
                    min = arr[i];
                }
                sum += arr[i];
            }
            avg = (double)sum / arr.Length;
            return sum;    
        }
        static int Rmine(int [] arr,ref int max,ref int min,ref double avg) 
        {
            int sum = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i]>max)
                {
                    max = arr[i];
                }
                if (arr[i]<min)
                {
                    min = arr[i];
                }
                sum += arr[i];
            }
            avg = (double)sum / arr.Length;
            return sum;
        }
    }
}
